/*  ----------------------------------------------------------------------------
 *  Arello Mobile
 *  Fast 3d Engine
 *  ----------------------------------------------------------------------------
 * Except where otherwise noted, this work is licensed under
 * http://creativecommons.org/licenses/by/3.0
 */

#ifndef __LIB3D_HARD_DIRECTX8_INDEX_BUFFER_H__
#define __LIB3D_HARD_DIRECTX8_INDEX_BUFFER_H__

#include <lib3d/hard/IndexBuffer.h>
#include "Dependent.h"
#include <d3d9.h>

namespace liba
{
namespace lib3d
{
namespace hard
{
namespace directx8
{
class Hardware;

class IndexBuffer : public hard::IndexBuffer, public Dependent
{
	IDirect3DIndexBuffer9 * index_buffer;

	int indices_count;
	bool valid_flag;
	const int max_vertex_index;

	template<class T>
	bool update( const int * indices, int indices_count, D3DFORMAT format );
public:
	explicit IndexBuffer(Hardware * hardware, int max_vertex_index);
	virtual ~IndexBuffer();
	virtual bool is_valid()const;
	virtual bool update( const int * indices, int indices_count );
	virtual bool render( int index_pos, int primitive_count, int vertex_pos, int vertex_count );

	virtual void invalidate();
	virtual void release();
};

} // namespace directx8
} // namespace hard
} // namespace lib3d
} // namespace liba
using namespace liba;

#endif //__LIB3D_HARD_DIRECTX8_INDEX_BUFFER_H__